/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmPelayananResepPasien.java
 *
 * Created on Jan 25, 2012, 10:00:01 AM
 */
package SIMRS.Apotek.view;

import SIMRS.Apotek.sql.KoneksiDatabase;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import usu.widget.Form;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author yunniie
 */
public class frmPelayananResepPasien extends Form {

    private static DefaultTableModel model;
Connection koneksi=KoneksiDatabase.getKoneksi();
    /** Creates new form frmPelayananResepPasien */
    public frmPelayananResepPasien() {
        initComponents();
        
        model=new DefaultTableModel();
        tblPelayananResepPasien.setModel(model);
        model.addColumn("Kode Obat");
        model.addColumn("Nama Obat");
        model.addColumn("Jumlah");
        model.addColumn("Harga");
        
        txtHarga.setEnabled(false);
        
        Date tanggal = new Date();
        txtTanggalResep.setDate(tanggal);
        
         cmbNamaBarang.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from obat order by NamaBarang asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbNamaBarang.addItem(rs.getString("NamaBarang"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }

        
        cmbDokter.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from pegawai order by Nama asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbDokter.addItem(rs.getString("Nama"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }

        
        cmbRuangan.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from ruangan order by NamaRuangan asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbRuangan.addItem(rs.getString("NamaRuangan"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }

        
        cmbUser.addItem("");
        try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select * from pegawai order by Nama asc");
         rs.beforeFirst();
         while(rs.next()){
             cmbUser.addItem(rs.getString("Nama"));
         }
         rs.close();
     }
     catch(SQLException ex)
     {
         System.out.println("Error : "+ex);
         }

        
        setIconImage(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/icon.png")).getImage());
        setTitle(".:: Form Pelayanan Resep Pasien");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlForm1 = new SIMRS.Apotek.widget.PnlForm();
        label1 = new SIMRS.Apotek.widget.Label();
        txtNoRegistrasi = new SIMRS.Apotek.widget.TextBox();
        label3 = new SIMRS.Apotek.widget.Label();
        txtNoRM = new SIMRS.Apotek.widget.TextBox();
        label4 = new SIMRS.Apotek.widget.Label();
        txtNama = new SIMRS.Apotek.widget.TextBox();
        label5 = new SIMRS.Apotek.widget.Label();
        cmbDokter = new javax.swing.JComboBox();
        label6 = new SIMRS.Apotek.widget.Label();
        txtUmur = new SIMRS.Apotek.widget.TextBox();
        pnlPelayananResepKaryawan = new javax.swing.JPanel();
        scrollPane1 = new SIMRS.Apotek.widget.ScrollPane();
        tblPelayananResepPasien = new SIMRS.Apotek.widget.Table();
        txtTotal = new SIMRS.Apotek.widget.TextBox();
        label9 = new SIMRS.Apotek.widget.Label();
        btnTambah = new SIMRS.Apotek.widget.button2();
        btnHapus = new SIMRS.Apotek.widget.button2();
        label7 = new SIMRS.Apotek.widget.Label();
        txtTanggalResep = new com.toedter.calendar.JDateChooser();
        label8 = new SIMRS.Apotek.widget.Label();
        label10 = new SIMRS.Apotek.widget.Label();
        label11 = new SIMRS.Apotek.widget.Label();
        cmbNamaBarang = new javax.swing.JComboBox();
        txtJumlah = new SIMRS.Apotek.widget.TextBox();
        txtHarga = new SIMRS.Apotek.widget.TextBox();
        kdBarang = new javax.swing.JTextField();
        btnCetak = new SIMRS.Apotek.widget.button2();
        btnSimpan = new SIMRS.Apotek.widget.button2();
        btnBatal = new SIMRS.Apotek.widget.button2();
        btnTutup = new SIMRS.Apotek.widget.button2();
        label13 = new SIMRS.Apotek.widget.Label();
        label2 = new SIMRS.Apotek.widget.Label();
        txtNoResep = new SIMRS.Apotek.widget.TextBox();
        kdDokter = new javax.swing.JTextField();
        label12 = new SIMRS.Apotek.widget.Label();
        cmbRuangan = new javax.swing.JComboBox();
        kdRuangan = new javax.swing.JTextField();
        label14 = new SIMRS.Apotek.widget.Label();
        cmbUser = new javax.swing.JComboBox();
        kdUser = new javax.swing.JTextField();

        setTitle(".: Form Pelayanan Resep Pasien");
        setAnimationHide(usu.widget.constan.Animation.HIDE_TO_BOTTOM);
        setAnimationShow(usu.widget.constan.Animation.SHOW_FROM_LEFT);
        setUndecorated(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        pnlForm1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(57, 190, 53), 3, true));
        pnlForm1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        label1.setText("No Resep");
        pnlForm1.add(label1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 70, 20));
        pnlForm1.add(txtNoRegistrasi, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 190, 110, -1));

        label3.setText("No RM");
        pnlForm1.add(label3, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 170, 100, 20));

        txtNoRM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNoRMActionPerformed(evt);
            }
        });
        pnlForm1.add(txtNoRM, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 190, 100, -1));

        label4.setText("Nama Pasien");
        pnlForm1.add(label4, new org.netbeans.lib.awtextra.AbsoluteConstraints(360, 170, 100, 20));

        txtNama.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNamaActionPerformed(evt);
            }
        });
        pnlForm1.add(txtNama, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 190, 170, -1));

        label5.setText("Dokter");
        pnlForm1.add(label5, new org.netbeans.lib.awtextra.AbsoluteConstraints(540, 170, 50, 20));

        cmbDokter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbDokterActionPerformed(evt);
            }
        });
        pnlForm1.add(cmbDokter, new org.netbeans.lib.awtextra.AbsoluteConstraints(530, 190, 150, -1));

        label6.setText("Umur");
        pnlForm1.add(label6, new org.netbeans.lib.awtextra.AbsoluteConstraints(700, 170, 50, 20));

        txtUmur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUmurActionPerformed(evt);
            }
        });
        pnlForm1.add(txtUmur, new org.netbeans.lib.awtextra.AbsoluteConstraints(690, 190, 70, -1));

        pnlPelayananResepKaryawan.setBackground(new java.awt.Color(51, 51, 51));
        pnlPelayananResepKaryawan.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlPelayananResepKaryawan.setOpaque(false);

        tblPelayananResepPasien.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        scrollPane1.setViewportView(tblPelayananResepPasien);

        label9.setText("Total");

        btnTambah.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_tambah.png"))); // NOI18N
        btnTambah.setText("Tambah");
        btnTambah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTambahActionPerformed(evt);
            }
        });

        btnHapus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_hapus.png"))); // NOI18N
        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        label7.setText("Tanggal Resep");

        label8.setText("Nama Obat");

        label10.setText("Jumlah");

        label11.setText("Harga");

        cmbNamaBarang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbNamaBarangActionPerformed(evt);
            }
        });

        kdBarang.setForeground(new java.awt.Color(255, 255, 51));
        kdBarang.setBorder(null);
        kdBarang.setFocusable(false);
        kdBarang.setOpaque(false);

        javax.swing.GroupLayout pnlPelayananResepKaryawanLayout = new javax.swing.GroupLayout(pnlPelayananResepKaryawan);
        pnlPelayananResepKaryawan.setLayout(pnlPelayananResepKaryawanLayout);
        pnlPelayananResepKaryawanLayout.setHorizontalGroup(
            pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addComponent(scrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 660, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(29, Short.MAX_VALUE))
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addComponent(btnTambah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(13, 13, 13)
                        .addComponent(btnHapus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 219, Short.MAX_VALUE)
                        .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                                .addGap(50, 50, 50)
                                .addComponent(label9, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtTanggalResep, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(43, 43, 43))))
            .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(label8, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(kdBarang, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cmbNamaBarang, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtJumlah, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addComponent(label10, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17)))
                .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addGap(54, 54, 54)
                        .addComponent(label11, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(265, Short.MAX_VALUE))
        );
        pnlPelayananResepKaryawanLayout.setVerticalGroup(
            pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPelayananResepKaryawanLayout.createSequentialGroup()
                .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(label8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(label10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(kdBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmbNamaBarang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addComponent(scrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 16, Short.MAX_VALUE)
                        .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btnTambah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnHapus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(23, 23, 23))
                    .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlPelayananResepKaryawanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                                .addComponent(label9, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlPelayananResepKaryawanLayout.createSequentialGroup()
                                .addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(6, 6, 6)
                                .addComponent(txtTanggalResep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );

        pnlForm1.add(pnlPelayananResepKaryawan, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 280, 720, 360));

        btnCetak.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_cetak.png"))); // NOI18N
        btnCetak.setText("Cetak Resep");
        pnlForm1.add(btnCetak, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 670, -1, -1));

        btnSimpan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_simpan.png"))); // NOI18N
        btnSimpan.setText("Simpan");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });
        pnlForm1.add(btnSimpan, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 670, -1, -1));

        btnBatal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_batal.png"))); // NOI18N
        btnBatal.setText("Batal");
        pnlForm1.add(btnBatal, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 670, -1, -1));

        btnTutup.setIcon(new javax.swing.ImageIcon(getClass().getResource("/SIMRS/Apotek/gambar/bt_close.png"))); // NOI18N
        btnTutup.setText("Tutup");
        btnTutup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTutupActionPerformed(evt);
            }
        });
        pnlForm1.add(btnTutup, new org.netbeans.lib.awtextra.AbsoluteConstraints(640, 670, -1, -1));

        label13.setForeground(new java.awt.Color(255, 255, 255));
        label13.setText("Pelayanan Resep Pasien");
        label13.setFont(new java.awt.Font("Tahoma", 1, 18));
        pnlForm1.add(label13, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 50, 400, -1));

        label2.setText("No Registrasi");
        pnlForm1.add(label2, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 170, 110, 20));
        pnlForm1.add(txtNoResep, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, 100, -1));

        kdDokter.setForeground(new java.awt.Color(255, 255, 0));
        kdDokter.setBorder(null);
        kdDokter.setFocusable(false);
        kdDokter.setOpaque(false);
        pnlForm1.add(kdDokter, new org.netbeans.lib.awtextra.AbsoluteConstraints(600, 170, 90, -1));

        label12.setText("Ruangan Asal");
        pnlForm1.add(label12, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 230, 80, -1));

        cmbRuangan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbRuanganActionPerformed(evt);
            }
        });
        pnlForm1.add(cmbRuangan, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 250, 170, -1));

        kdRuangan.setForeground(new java.awt.Color(255, 255, 0));
        kdRuangan.setBorder(null);
        kdRuangan.setFocusable(false);
        kdRuangan.setOpaque(false);
        pnlForm1.add(kdRuangan, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 230, 70, -1));

        label14.setText("User");
        pnlForm1.add(label14, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 230, 40, -1));

        cmbUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbUserActionPerformed(evt);
            }
        });
        pnlForm1.add(cmbUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 250, 140, -1));

        kdUser.setForeground(new java.awt.Color(204, 204, 0));
        kdUser.setBorder(null);
        kdUser.setFocusable(false);
        kdUser.setOpaque(false);
        pnlForm1.add(kdUser, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 230, 80, -1));

        getContentPane().add(pnlForm1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 780, 720));

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-779)/2, (screenSize.height-721)/2, 779, 721);
    }// </editor-fold>//GEN-END:initComponents

private void txtNoRMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNoRMActionPerformed
// TODO add your handling code here:
    System.exit(1);
}//GEN-LAST:event_txtNoRMActionPerformed

private void txtNamaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNamaActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtNamaActionPerformed

private void txtUmurActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUmurActionPerformed
// TODO add your handling code here:
    Connection c=KoneksiDatabase.getKoneksi();
        try {
            Statement s=c.createStatement();
            String sql="SELECT HitungUmur(TanggalLahir);";
            
            ResultSet rs=s.executeQuery(sql);
       //     txtUmur.setText(sql);
            System.out.println("umurnya "+rs);
        } catch (SQLException ex) {
            
        }
   
    
}//GEN-LAST:event_txtUmurActionPerformed

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
    System.exit(1);
}//GEN-LAST:event_formWindowClosing

private void btnTutupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTutupActionPerformed
    dispose();
}//GEN-LAST:event_btnTutupActionPerformed

private void cmbRuanganActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbRuanganActionPerformed
// TODO add your handling code here:
    try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select KdRuangan from ruangan where NamaRuangan= '"+cmbRuangan.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             kdRuangan.setText(rs.getString(1).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
}//GEN-LAST:event_cmbRuanganActionPerformed

private void cmbUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbUserActionPerformed
// TODO add your handling code here:
    try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select IdPegawai from pegawai where Nama= '"+cmbUser.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             kdUser.setText(rs.getString(1).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
}//GEN-LAST:event_cmbUserActionPerformed

private void cmbNamaBarangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbNamaBarangActionPerformed
// TODO add your handling code here:
    try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("SELECT obat.KdBarang, hargabarangmedis.HargaNetto1 FROM obat JOIN hargabarangmedis ON (obat.KdBarang=hargabarangmedis.KdBarang) where obat.NamaBarang= '"+cmbNamaBarang.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             kdBarang.setText(rs.getString(1).trim());
             txtHarga.setText(rs.getString(2).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
}//GEN-LAST:event_cmbNamaBarangActionPerformed

private void cmbDokterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbDokterActionPerformed
// TODO add your handling code here:
    try{
         Statement stm = koneksi.createStatement();
         ResultSet rs = stm.executeQuery("select IdPegawai from pegawai where Nama= '"+cmbDokter.getSelectedItem().toString()+"'");
         rs.beforeFirst();
         while(rs.next()){
             kdDokter.setText(rs.getString(1).trim());
         }
         rs.close();
         }
         catch(SQLException ex)
         {
             System.out.println("Error : "+ex);
             }
}//GEN-LAST:event_cmbDokterActionPerformed

private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTambahActionPerformed
// TODO add your handling code here:
    
    String []a=new String[4];
        a[0]=kdBarang.getText();
        a[1]=cmbNamaBarang.getSelectedItem().toString();
        a[2]=txtJumlah.getText();
        a[3]=txtHarga.getText();
        hitung_total();   
        model.addRow(a); 
}//GEN-LAST:event_btnTambahActionPerformed

private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapusActionPerformed
// TODO add your handling code here:
    int row=tblPelayananResepPasien.getSelectedRow();
    model.removeRow(row);
    
}//GEN-LAST:event_btnHapusActionPerformed

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanActionPerformed
        // TODO add your handling code here:
       Connection c = KoneksiDatabase.getKoneksi();
    if (tblPelayananResepPasien.getRowCount() == 0) {
        JOptionPane.showMessageDialog(null, "Data Masih Kosong..!!", "Warning", JOptionPane.INFORMATION_MESSAGE);
    } else {
        try {
            String noResep = txtNoResep.getText();
            String noReg= txtNoRegistrasi.getText();
             String noRekamMedis= txtNoRM.getText();
            String Ruang = kdRuangan.getText();
            SimpleDateFormat Format = new SimpleDateFormat("yyyy-MM-dd");
            String tanggal = Format.format(txtTanggalResep.getDate());
            String noDokter= kdDokter.getText();
            String User= kdUser.getText();
            String tot = txtTotal.getText();
            
            
            Statement stm = c.createStatement();
           String sql = "insert into resepobat values('" + noResep + "','" + tanggal + "','" + noDokter + "','" + Ruang + "','" + User + "')";
          

         stm.executeUpdate(sql);
           

            for (int i = 0; i < tblPelayananResepPasien.getRowCount(); i++) {

                    String barang = (String) tblPelayananResepPasien.getValueAt(i, 0);
                    String jml= (String) tblPelayananResepPasien.getValueAt(i, 2);
                    String harga= (String) tblPelayananResepPasien.getValueAt(i, 3);
                    

                 String sql1 = "insert into transaksiresep values('" + noResep + "','" + barang + "','" + noReg + "','" + noRekamMedis + "','" + jml + "','" + harga + "','" + tot + "')";

                  stm.executeUpdate(sql1);

                }
            
            JOptionPane.showMessageDialog(this, "Data Berhasil Disimpan");
           
            txtNoResep.setText("");
            txtNoRegistrasi.setText("");
            txtNama.setText("");
            txtNoRM.setText("");
            txtJumlah.setText("");
            txtHarga.setText("");
            txtTotal.setText("");
            kdBarang.setText("");
            kdRuangan.setText("");
            kdDokter.setText("");
            kdUser.setText("");
            cmbNamaBarang.setSelectedItem("");
            cmbUser.setSelectedItem("");
            cmbRuangan.setSelectedItem("");
            cmbDokter.setSelectedItem("");
            
            
            
        } catch (SQLException e) {
            System.out.println("Error : " + e);
            JOptionPane.showMessageDialog(this, "Data gagal disimpan");
        }
    }

        
    }//GEN-LAST:event_btnSimpanActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private SIMRS.Apotek.widget.button2 btnBatal;
    private SIMRS.Apotek.widget.button2 btnCetak;
    private SIMRS.Apotek.widget.button2 btnHapus;
    private SIMRS.Apotek.widget.button2 btnSimpan;
    private SIMRS.Apotek.widget.button2 btnTambah;
    private SIMRS.Apotek.widget.button2 btnTutup;
    private javax.swing.JComboBox cmbDokter;
    private javax.swing.JComboBox cmbNamaBarang;
    private javax.swing.JComboBox cmbRuangan;
    private javax.swing.JComboBox cmbUser;
    private javax.swing.JTextField kdBarang;
    private javax.swing.JTextField kdDokter;
    private javax.swing.JTextField kdRuangan;
    private javax.swing.JTextField kdUser;
    private SIMRS.Apotek.widget.Label label1;
    private SIMRS.Apotek.widget.Label label10;
    private SIMRS.Apotek.widget.Label label11;
    private SIMRS.Apotek.widget.Label label12;
    private SIMRS.Apotek.widget.Label label13;
    private SIMRS.Apotek.widget.Label label14;
    private SIMRS.Apotek.widget.Label label2;
    private SIMRS.Apotek.widget.Label label3;
    private SIMRS.Apotek.widget.Label label4;
    private SIMRS.Apotek.widget.Label label5;
    private SIMRS.Apotek.widget.Label label6;
    private SIMRS.Apotek.widget.Label label7;
    private SIMRS.Apotek.widget.Label label8;
    private SIMRS.Apotek.widget.Label label9;
    private SIMRS.Apotek.widget.PnlForm pnlForm1;
    private javax.swing.JPanel pnlPelayananResepKaryawan;
    private SIMRS.Apotek.widget.ScrollPane scrollPane1;
    private SIMRS.Apotek.widget.Table tblPelayananResepPasien;
    private SIMRS.Apotek.widget.TextBox txtHarga;
    private SIMRS.Apotek.widget.TextBox txtJumlah;
    private SIMRS.Apotek.widget.TextBox txtNama;
    private SIMRS.Apotek.widget.TextBox txtNoRM;
    private SIMRS.Apotek.widget.TextBox txtNoRegistrasi;
    private SIMRS.Apotek.widget.TextBox txtNoResep;
    private com.toedter.calendar.JDateChooser txtTanggalResep;
    private SIMRS.Apotek.widget.TextBox txtTotal;
    private SIMRS.Apotek.widget.TextBox txtUmur;
    // End of variables declaration//GEN-END:variables

public void isiText(String noResep, String noReg, String noRM, String pasien, String dokter, String umur, String ruang, String user, String nmBarang, String jmlh, String harga, Date a, String tot){
  txtNoResep.setText(noResep);
  txtNoRegistrasi.setText(noReg);
  txtNoRM.setText(noRM);
  txtNama.setText(pasien);
  cmbDokter.setSelectedItem(dokter);
 // txtUmur.setText(umur);
  cmbRuangan.setSelectedItem(ruang);
  cmbUser.setSelectedItem(user);
  cmbNamaBarang.setSelectedItem(nmBarang);
  txtJumlah.setText(jmlh);
  txtHarga.setText(harga);
  txtTanggalResep.setDate(a);
//  txtTotal.setText(tot);
  
}

private float hitung_total(){
       
       int jml, hrga;
       float xtot;
       
       xtot=0;
       jml = Integer.parseInt(txtJumlah.getText());
       hrga=Integer.parseInt(txtHarga.getText());
       xtot = jml*hrga;
       for (int i = 0; i < tblPelayananResepPasien.getRowCount(); i++) {
           xtot=xtot+xtot;
       }
       
       tblPelayananResepPasien.getCellRenderer(jml, 3);
       
       String xjml = Float.toString(xtot);
       txtTotal.setText(xjml);
 
       return xtot;
        
    }


}
